package com.sssoft.Yundian.activity;

import java.util.List;

import org.w3c.dom.Text;

import com.sssoft.Yundian.R;
import com.sssoft.Yundian.Dao.IncomeDao;
import com.sssoft.Yundian.bean.IncomeBean;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author 商品详情页
 *
 */
public class OrdersDetailsActivity extends Activity{
	private List<IncomeBean> details_list;
	private IncomeDao iDao;
	private TextView tv_orders_num;
	private TextView tv_orders_state;
	private TextView tv_orders_date;
	private TextView tv_orders_method;
	private TextView tv_orders_total_price;
	private TextView tv_orders_actual_price;
	// 订单商品详情list
	private ListView lv_goods_details;
	
	private Button bt_print_ticket;
	private Button bt_refunds;
	
	private TextView tv_goods_name;
	private TextView tv_goods_price;
	private TextView tv_goods_num;
	private TextView tv_goods_total_price;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_orders_details);
		iDao = new IncomeDao(this);		
		lv_goods_details = (ListView) findViewById(R.id.lv_goods_details);
		//获取MyIncome所传值
		Intent intent = getIntent();
		//订单号
		final String OrdersNum = intent.getStringExtra("OrdersNum");
		String OrdersState = intent.getStringExtra("OrdersState");
		String OrdersDate = intent.getStringExtra("OrdersDate");
		String OrdersMethod = intent.getStringExtra("OrdersMethod");
		String OrdersTotalPrice = intent.getStringExtra("OrdersTotalPrice");
		String OrdersActualPrice = intent.getStringExtra("OrdersActualPrice");
		tv_orders_num = (TextView) findViewById(R.id.tv_orders_number);
		tv_orders_state = (TextView) findViewById(R.id.tv_orders_state);
		tv_orders_date = (TextView) findViewById(R.id.tv_orders_date);
		tv_orders_method = (TextView) findViewById(R.id.tv_orders_method);
		tv_orders_total_price = (TextView) findViewById(R.id.tv_orders_total_price);
		tv_orders_actual_price = (TextView) findViewById(R.id.tv_orders_actual_price);
		tv_orders_num.setText(OrdersNum);
		tv_orders_state.setText(OrdersState);
		tv_orders_date.setText(OrdersDate);
		tv_orders_method.setText(OrdersMethod);
		tv_orders_total_price.setText(OrdersTotalPrice);
		tv_orders_actual_price.setText(OrdersActualPrice);
		//根据订单号查询数据库,获取商品详情
		details_list = iDao.list_goods_details(OrdersNum);
//		Toast.makeText(OrdersDetails.this, ""+details_list+"", Toast.LENGTH_LONG).show();
		//打印小票
//		bt_print_ticket =(Button) findViewById(R.id.bt_print_ticket);
//		bt_print_ticket.setOnClickListener(this);
//		//退款
//		bt_refunds =(Button) findViewById(R.id.bt_refunds);
//		bt_refunds.setOnClickListener(this);
		//商品详情底部listview适配器
		BaseAdapter bAdapter = new BaseAdapter() {
			@Override
			public int getCount(){
				return details_list.size();
			}
			@Override
			public Object getItem(int pos) {
				// TODO Auto-generated method stub
				return null;
			}
			@Override
			public long getItemId(int pos) {
				// TODO Auto-generated method stub
				return pos;
			}
			@Override
			public View getView(int pos, View goods_view, ViewGroup arg2) {
				// TODO Auto-generated method stub
				View detail_view = goods_view != null ? goods_view
						: View.inflate(getApplicationContext(), R.layout.listview_details_orders, null);
				tv_goods_name = (TextView) detail_view.findViewById(R.id.tv_goods_name);
				tv_goods_price = (TextView) detail_view.findViewById(R.id.tv_goods_price);
				tv_goods_num = (TextView) detail_view.findViewById(R.id.tv_goods_num);
				tv_goods_total_price = (TextView) detail_view.findViewById(R.id.tv_goods_total_price);
				//获取数据库查询商品详情
				IncomeBean dlist = details_list.get(pos);
				tv_goods_name.setText(dlist.getGoods_name());
				tv_goods_price.setText(dlist.getGoods_price());
				tv_goods_num.setText(dlist.getGoods_details_num());
				tv_goods_total_price.setText(dlist.getGoods_details_total_price());
				return detail_view;
			}
		};
		lv_goods_details.setAdapter(bAdapter);
		
		
	}
//	//打印小票和退款button点击事件
//	public void onClick(View v){
//				switch (v.getId()) {
//				case R.id.bt_refunds:
//					Boolean order_alter = IncomeDao.order_alter(Orders_num);
//					
//					break;
//
//				default:
//					break;
//				}
//			}

}




